package com.tyqx.hashchainbiz.controller.useProduct;

import com.tyqx.hashchainbean.module.BuyProduct;
import com.tyqx.hashchainbean.vo.*;
import com.tyqx.hashchainbiz.service.BuyProductService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "采购物资")
@RestController
@RequestMapping("/buyProduct")
@CrossOrigin
public class BuyProductController {

    @Resource
    private BuyProductService buyProductService;

    @RequestMapping(value="/saveBuyProduct", method = RequestMethod.POST)
    @ResponseBody
    public String saveBuyProduct(@RequestBody BuyProductVO buyProductVO) throws Exception {

        String msg="";
        BuyProduct buyProduct=new BuyProduct();
        //buyProduct.setAttachment(buyProductVO.getAttachment());
        buyProduct.setBuyName(buyProductVO.getBuyName());
        buyProduct.setBuyNum(buyProductVO.getBuyNum());
        buyProduct.setBuyPrice(buyProductVO.getBuyPrice());
        buyProduct.setBuyTime(buyProductVO.getBuyTime());
        buyProduct.setBuyUnit(buyProductVO.getBuyUnit());
        buyProduct.setDonateId(buyProductVO.getDonateId());
        buyProduct.setOperator(buyProductVO.getOperator());
        buyProduct.setSupportDept(buyProductVO.getSupportDept());
        buyProduct.setUserName(buyProductVO.getUserName());

        if(buyProductService.buyProduct(buyProduct)>0){
            msg="添加采购物资成功";
        }else{
            msg="添加采购物资失败";
        }
        return msg;
    }

    @RequestMapping(value="/getBuyProductById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<BuyProduct> getBuyProductById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return buyProductService.getBuyProductById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getBuyProductByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<BuyProduct> getBuyProductByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        List<BuyProduct> buyProducts= buyProductService.getBuyProductByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
        return buyProducts;
    }
}
